package com.ganwei.mybatisplus.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ganwei.mybatisplus.system.pojo.Product;
import com.ganwei.mybatisplus.system.mapper.ProductMapper;
import com.ganwei.mybatisplus.system.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ganwei
 * @since 2020-10-08
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Resource
    private ProductMapper productMapper;

    @Override
    public Page<Product> pageProduct(Integer pageNum, Integer pageSize,String searchName) {
        QueryWrapper<Product> wrapper = new QueryWrapper<>();
        //notLike 不包含该字段
        if(searchName != "" && searchName != null) {
            wrapper.like("productname", searchName)
                    .or().like("desc1", searchName);
        }
        Page<Product> page = new Page<>(pageNum, pageSize);
        return (Page<Product>) productMapper.selectPage(page,wrapper);
    }

    @Override
    public int updateProduct(Product product) {
        Product product1 = new Product();
        product1.setId(product.getId());
        product1.setStatus(product.getStatus());
        return productMapper.updateById(product1);
    }
}
